<?php
class PNExtPersonArray extends PNObjectExArray {
  function PNExtPersonArray($init=null, $where='')
  {
    $this->PNObject();

    $this->_objType       = 'votedatacenter_extperson';
    $this->_objField      = 'id';
    $this->_objPath       = 'form';

    $this->_objJoin[]     = array ( 'join_table'  =>  'votedatacenter_province',
                            'join_field'          =>  array('name'),
                            'object_field_name'   =>  array('pro_name'),
                            'compare_field_table' =>  'pro_id',
                            'compare_field_join'  =>  'id');

    $this->_objJoin[]     = array ( 'join_table'  =>  'votedatacenter_district',
                            'join_field'          =>  array('name'),
                            'object_field_name'   =>  array('dis_name'),
                            'compare_field_table' =>  'dis_id',
                            'compare_field_join'  =>  'id');

    $this->_objJoin[]     = array ( 'join_table'  =>  'votedatacenter_tambon',
                            'join_field'          =>  array('name'),
                            'object_field_name'   =>  array('tam_name'),
                            'compare_field_table' =>  'tam_id',
                            'compare_field_join'  =>  'id');


    $this->_objJoin[]     = array ( 'join_table'  =>  'votedatacenter_gender',
                            'join_field'          =>  array('name'),
                            'object_field_name'   =>  array('gen_name'),
                            'compare_field_table' =>  'gen_id',
                            'compare_field_join'  =>  'id');


    $this->_init($init, $where);
  }

  function genSort(){
    //return " ORDER BY pro_name ,dis_name ,tam_name ,vil_name ASC";
    return " ORDER BY pro_name, dis_name, tam_name, exp_firstname ASC";
  }

  function genFilter(){

/*
    $keyword  = FormUtil::getPassedValue ('keyword', false);
    $type  = FormUtil::getPassedValue ('type', false);
    $wheres = array();
    var_dump($type); 
    if ($keyword && $type == "firstname") $wheres[] = " exp_firstname like %'".$keyword."'%";
    if ($keyword && $type == "lastname") $wheres[] = " exp_lastname like %'".$keyword."'%";
*/

    $keyword  = FormUtil::getPassedValue ('keyword', false);
    var_dump($keyword);
    $wheres = array();
    if($keyword){
      $wheres[] = " exp_firstname like '%".$keyword."%' OR  exp_lastname like '%".$keyword."%'" ;
    }
    var_dump($wheres); 
    return implode(' AND ', $wheres) ;
  }


}
